import request from '@/utils/http'

export interface SysConfig {
  // 基础信息
  system_name: string
  language_default: string
  timezone: string
  // 邮件
  smtp_enable: boolean
  smtp_host: string
  smtp_port: number
  smtp_ssl: boolean
  smtp_protocol?: 'SMTP' | 'SMTPS'
  smtp_user: string
  smtp_password: string
  smtp_from_name: string
  smtp_from_mail: string
  // 登录
  login_retry_limit: number
  login_lock_minutes: number
  captcha_required: boolean
  multi_device_login: boolean
  remember_me_days: number
  // 安全
  password_min_length: number
  password_require_upper: boolean
  password_require_lower: boolean
  password_require_number: boolean
  password_require_symbol: boolean
  jwt_secret: string
  jwt_expire_minutes: number
  refresh_expire_days: number
  allow_origins: string
  rate_limit_per_min: number
  // 会话/令牌
  session_timeout_minutes: number
  token_header_name: string
  token_issuer: string
  token_audience: string
  token_algorithm: 'HS256' | 'HS384' | 'HS512'
  // 通知
  notify_email_enable: boolean
  notify_webhook_enable: boolean
  webhook_url: string
  // 文件/上传
  upload_max_size_mb: number
  upload_allowed_types: string
  upload_storage_backend: 'local' | 's3'
  // 第三方集成
  oauth_login_enable: boolean
  oauth_github_client_id: string
  oauth_github_client_secret: string
  oauth_google_client_id: string
  oauth_google_client_secret: string
  // 功能开关
  enable_registration: boolean
  enable_audit_log: boolean
  data_retention_days: number
}

export function fetchSysConfig() {
  return request.get<any, SysConfig>('/system/config')
}

export function updateSysConfig(data: SysConfig) {
  return request.put('/system/config', data)
}